package com.cq.service.impl;

import com.cq.mapper.FileMapper;
import com.cq.pojo.File;
import com.cq.service.FileService;
import com.cq.utils.FastDFSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 悠久的苍穹
 * @Date: 2021/1/16 17:45
 * @Description: ${description}
 * @Version: 1.0
 */
@Service
public class FileServiceImpl implements FileService {

    @Autowired
    FileMapper fileMapper;

    @Override
    public List<File> getFile(Integer page,Integer limit) {
        return fileMapper.getFile((page-1)*limit,limit);
    }

    @Override
    public void addFile(String url, String name) {
        fileMapper.addFile(url,name);
    }

    @Override
    public Integer getCount() {
        return fileMapper.getCount();
    }

    @Override
    public int deleteById(int id) {
        File file = fileMapper.getFileById(id);
        FastDFSUtil.deleteFile(file.getUrl());
        return fileMapper.deleteById(id);
    }
}
